package cn.regexp.seckill.util;

import java.util.Calendar;
import java.util.Date;

/**
 * @author Regexpei
 * @date 2024/7/5 23:33
 * @description 日期工具类
 */
public class DateUtil {
    /**
     * 根据日期和场次看是否在秒杀有效时间之内
     *
     * @param date 日期
     * @param time 场次
     * @return 是否在秒杀有效时间之内
     */
    public static boolean isLegalTime(Date date, int time) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY, time);
        long start = c.getTime().getTime();
        long now = new Date().getTime();
        c.add(Calendar.HOUR_OF_DAY, 2);
        long end = c.getTime().getTime();
        return now >= start && now <= end;
    }
}
